#include <iostream>
using namespace std;
int shiliujinzhi(int x);
int shierjinzhi(int y);
int main()
{
    for(int a=2992;a<=9999;a++)
       {int sum=0;int  n=a;
         while(n!=0)
          {sum+=n%10;
           n=n/10;
           }
         
         if(sum==shiliujinzhi(a)&&sum==shierjinzhi(a)  ) 
                cout<<a<<endl;
       }
       
       
system("pause");
return 0;
}



int shiliujinzhi(int x)
{int s1=0;int m=4096;
 for(int i=1;i<=4;i++)
 {s1+=x/m;
  x=x%m;
  m=m/16;
} 
  return s1;      
}                



int shierjinzhi(int y)
{int s2=0;int m=1728;
 for(int i=1;i<=4;i++)
 {s2+=y/m;
  y=y%m;
  m=m/12;
} 
return s2;
}                
